package com.usian.wemedia.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.api.wemedia.WmUserControllerApi;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.service.WmUserService;
import com.usian.wemedia.service.impl.WmUserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/user")
public class WmUserController implements WmUserControllerApi {

    @Autowired
    private WmUserServiceImpl service;

    @PostMapping("/save")
     @Override
    public ResponseResult save(@RequestBody WmUser dto){
        if (dto==null)return service.errorParam;
        service.save(dto);
        return service.success;
    }

    @GetMapping("/findByName/{name}")
    @Override
    public WmUser findByName(@PathVariable("name") String name){
//        List<WmUser> list = userService.list(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName, name));
//        if(list!=null && !list.isEmpty()){
//            return list.get(0);
//        }
        return service.getOne(Wrappers.<WmUser>lambdaQuery().eq(StringUtils.isNotEmpty(name), WmUser::getName, name));
    }
}